define(function(require, exports, module) {

	var $ = require('jquery');
	require('artTemplate/artTemplate/2.0.1/template.js');
	require('jquery/jquery-form/1.0.0/jquery.form.js');
	require('jquery/jquery-json/2.4.0/jquery.json.js');
	require('seajs/seajs/2.1.1/sea.js');

	exports.options = {
		listLink : '',
		listParams : '',
		pageLink : '',
		pageParams : ''
	};
	var status='';

	//mark
	$("#status_select").change(function(){
		if($(this).val()==3){
			$(this).next().next().show();
		}else if($(this).val()==1){
			$(this).next().next().empty().hide();
		}else if($(this).val()==2){
			$(this).next().next().empty().hide();
		}
	})
	//提交项目信息
	$('.add-submit').click(function(){
		var postData = form2js('update-form', '.', true);
		status=postData.status;
		$.ajax({
			url : $CONFIG.base_url + "/api/admin/institution/update",
			type : "POST",
			data : $.toJSON(postData),
			dataType : "json",
			contentType : "application/json",
			success : function() {
				$.jBox.tip("更新信息成功!");
				if(status == 1)
					setTimeout(function(){window.location.href=$CONFIG.base_url + '/'+$CONFIG.admin_url+'/verify/user';},1000);
				else if(status == 2)
					exports.send_success();
				else if(status == 3)
					exports.send_fail();
			},
			error : function() {
				$.jBox.tip("更新信息失败!");
			}
		});
	});

	//发送系统通知
	exports.send_success = function (){
		$("#content").val($("#reason").val());
		var postData = new Object();
		postData.messageFrom={"id":g_user.id};
		postData.content = "恭喜您，认证个人服务商成功！";
		postData.messageTo = {"id": $("#userId").val()};
		console.log($.toJSON(postData));
		$.ajax({
			url : $CONFIG.base_url + "/api/message/add",
			type : "POST",
			data : $.toJSON(postData),
			dataType : "json",
			contentType : "application/json",
			success : function() {
				setTimeout(function(){window.location.href=$CONFIG.base_url + '/'+$CONFIG.admin_url+'/verify/user';},1000);
			},
			error : function() {
				$.jBox.tip("系统通知失败！");
			}
		});
	}	

	exports.send_fail = function (){
		console.log($("#reason").val());
		var postData = new Object;
		postData.messageFrom={"id":g_user.id};
		postData.content = "抱歉，您的个人服务商认证失败，失败原因：" + $("#reason").val();
		postData.messageTo = {"id": $("#userId").val()};
		console.log($.toJSON(postData));
		$.ajax({
			url : $CONFIG.base_url + "/api/message/add",
			type : "POST",
			data : $.toJSON(postData),
			dataType : "json",
			contentType : "application/json",
			success : function() {
				setTimeout(function(){window.location.href=$CONFIG.base_url + '/'+$CONFIG.admin_url+'/verify/user';},1000);
			},
			error : function() {
				$.jBox.tip("系统通知失败！");
			}
		});
	}	
});